<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>外出申请单</title>
    <script src="/assets/js/config.js"></script>
    <link rel="stylesheet" type="text/css" href="css/apply.css"/>

    <script type="text/javascript" src="js/design.js"></script>
    <script type="text/javascript" src="js/multiSelect.js"></script>
</head>
<body>
<form id="fm">
    <h2 align=" center" id="title">外出申请单</h2>
    <p>申请日期： <span id="crtDate"></span></p>
    <table border="1" style="border-collapse: collapse;width: 100%">
        <tr>
            <td>姓名</td>
            <td><input class="layui-input" name="userName" readonly></td>
            <td>部门</td>
            <td><input class="layui-input" name="department" readonly></td>
            <td>外出时间</td>
            <td><input class="layui-input" name="leaveDate" id="startDate"></td>
        </tr>
        <tr>
            <td>外出事由</td>
            <td colspan="5"><textarea class="layui-textarea" name="reason"></textarea></td>
        </tr>
    </table>
</form>
</body>
<script>
    $(function () {
        var id = getUrlParam();
        if (id) {
            //审批进入
            drawApprove(id);
            $("input").prop('readonly', true);
            $("#app").hide();
            $(".layui-layer-btn").hide();
            $.post('/office/flowStepInstance/queryDetail', {id: id}, function (res) {
                if (res.code == 200) {
                    var data = res.obj;
                    drawForm(data, $("#fm"))
                    $("#crtDate").text(formatDate(new Date(data.crtDate)));
                    $("#radio" + data.tool).attr("checked", "checked");
                }
            })
        } else {
            var today = formatDate(new Date());
            drawAdd();
            $("#crtDate").text(today);
            $("[name='userName']").val(getUserName());
            $("[name='department']").val(getOrgName());
            //渲染流程
            $.post('/office/flowStepTemplate/getTemplateStep', {userId: getUserId(), templateId: 2}, function (res) {
                if (res.code == 200) {
                    if (res.obj) {
                        drawFlowStep(res.obj.flowNodes);
                    }
                }
            })
        }
    });

    function submitForm() {
        var param = getSubmitParam();
        if (!validateCommonForm()) {
            showAlert("请补全表单详情后提交哦");
            return false;
        }
        layer.confirm('确认提交', function (index) {
            param.userId = localStorage.getItem("userId");
            param.title = $("#title").text();
            param.tool = $("input[name='tool']:checked").val();
            doSubmit('/office/flowWork/addLeaveFlow', param);
        })
    }

</script>

</html>